/**
 * @desc 判断两个对象是否相等
 * @param obj1
 * @param obj2
 * @return Boolean
 */
function equal(obj1: object, obj2: object) {
    let result = true
    if (Array.isArray(obj1) !== Array.isArray(obj2))
        result = false
    if (Array.isArray(obj1) && Array.isArray(obj2)) {
        if (obj1.length !== obj2.length)
            result = false
        for (let i = 0; i < obj1.length; ++i) {
            if (typeof obj1[i] !== typeof obj2[i])
                result = false
            if (typeof obj1[i] === "object" && typeof obj2[i] === "object") {
                result = equal(obj1[i], obj2[i])
            } else {
                if (obj1[i] !== obj2[i])
                    result = false
            }
        }
    } else {
        if (Object.getOwnPropertyNames(obj1).length !== Object.getOwnPropertyNames(obj2).length)
            result = false
        if (Object.getOwnPropertySymbols(obj1).length !== Object.getOwnPropertySymbols(obj2).length)
            result = false

        const judge = function (ele) {
            if (!obj2[ele])
                result = false
            if (typeof obj1[ele] !== typeof obj2[ele])
                result = false
            if (typeof obj1[ele] === "object" && typeof obj2[ele] === "object") {
                result = equal(obj1[ele], obj2[ele])
            } else {
                if (obj1[ele] !== obj2[ele])
                    result = false
            }
        }

        Object.getOwnPropertyNames(obj1).forEach(ele => {
            judge(ele)
        })
        Object.getOwnPropertySymbols(obj1).forEach(ele => {
            judge(ele)
        })
    }
    return result
}

export default {
    equal,
}
